package com.carleasoft.mps.cms.business.train.schedule;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.carleasoft.mps.cms.business.train.bean.entity.TrainConsume;
import com.carleasoft.mps.cms.business.train.service.TrainConsumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description: 训练定时任务
 * @Author: fan
 */
@EnableScheduling
@Component
public class Schedule {
    @Autowired
    private TrainConsumeService trainConsumeService;

    /**
     * 每月一号一点重置消耗维护状态
     * "0 0 1 1 * ?" 每月一号 1:00:00 执行一次 0 0 22 1 * ?
     */
//    @Scheduled(cron = "0 0/10 * * * ?")//十分钟搞一次
    @Scheduled(cron = "0 0 1 1 * ?")
    public void trainConsumeSchedule(){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.err.println(dateFormat.format(new Date()));
        boolean status = trainConsumeService.update(new UpdateWrapper<TrainConsume>().set("STATUS", 1).eq("STATUS",2));
    }
}
